• 本例展示如何在alpha-mind中使用机器学习模型

  • 请在环境变量中设置DB_URI指向数据库


In [1]:
%matplotlib inline

import os
import datetime as dt
import numpy as np
import pandas as pd
from alphamind.api import *
from PyFin.api import *

数据配置



In [2]:
freq = '20b'
universe = Universe('zz800')
batch = 8
neutralized_risk = industry_styles
risk_model = 'short'
pre_process = [winsorize_normal, standardize]
post_process = [standardize]
warm_start = 0
data_source = os.environ['DB_URI']
horizon = map_freq(freq)

engine = SqlEngine(data_source)

我们使用当期的[ROE, EPS, ETOP]因子,来尝试预测未来大概一个月以后的收益。

  • 训练的股票池为zz800;;
  • 因子都经过中性化以及标准化等预处理;
  • 对于线性模型,我们以20个工作日为一个时间间隔,用过去8期的数据作为训练用特征。

In [3]:
fit_intercept = True
features = ['ROE', 'EPS', 'ETOP']

data_meta = DataMeta(freq=freq,
                     universe=universe,
                     batch=batch,
                     neutralized_risk=neutralized_risk,
                     risk_model=risk_model,
                     pre_process=pre_process,
                     post_process=post_process,
                     warm_start=warm_start,
                     data_source=data_source)

alpha_model = LinearRegression(features=features, fit_intercept=True)
composer = Composer(alpha_model=alpha_model, data_meta=data_meta)

start_date = '2011-01-01'
end_date = '2019-01-15'

模型预测



In [4]:
ref_date = '2017-01-31'
ref_date = adjustDateByCalendar('china.sse', ref_date).strftime('%Y-%m-%d')
model, x, y = composer.train(ref_date)

In [5]:
print("Testing IC: {0:.4f}".format(composer.ic(ref_date=ref_date)[0]))


Testing IC: -0.0580

模型对比 (线性回归模型 v.s. Naive - 常数线性模型)



In [6]:
const_model = ConstLinearModel(features=features, weights={f: 1. for f in features})
regression_model = LinearRegression(features=features, fit_intercept=fit_intercept)

const_composer = Composer(alpha_model=const_model, data_meta=data_meta)
regression_composer = Composer(alpha_model=regression_model, data_meta=data_meta)

In [7]:
const_composer.train(ref_date)
regression_composer.train(ref_date)
pass

In [8]:
print("\nConst. Testing IC: {0:.4f}".format(const_composer.ic(ref_date=ref_date)[0]))
print("Regression Testing IC: {0:.4f}".format(regression_composer.ic(ref_date=ref_date)[0]))


Const. Testing IC: -0.0413
Regression Testing IC: -0.0580

模型时间序列


通过比较在测试集的结果,我们观察如下两个模型的表现:

  • Naive Model:简单的使用因子上期值作为当期值的预测;
  • 线性回归模型:利用过去四期的因子值回归后得到模型,然后用这个模型预测当期值;

In [9]:
model_dates = makeSchedule(start_date, end_date, freq, 'china.sse')
model_dates = [d.strftime("%Y-%m-%d") for d in model_dates]

model_df = pd.DataFrame(columns=['naive', 'regress', 'naive ic.', 'regress ic.'])

test_data = {}

for ref_date in model_dates:
    regression_composer.train(ref_date)
    const_composer.train(ref_date)
    
    model_df.loc[ref_date, 'naive'] = const_composer[ref_date]
    model_df.loc[ref_date, 'regress'] = regression_composer[ref_date]
    model_df.loc[ref_date, 'naive ic.'], x, y  = const_composer.ic(ref_date=ref_date)
    model_df.loc[ref_date, 'regress ic.'], _, _ = regression_composer.ic(ref_date=ref_date, x=x, y=y)
    
    test_data[ref_date] = (x, y)

    print("\n{1} Const. Testing IC: {0:.4f}".format(model_df.loc[ref_date, 'naive ic.'], ref_date))
    print("{1} Regression Testing IC: {0:.4f}".format( model_df.loc[ref_date, 'regress ic.'], ref_date))


2011-01-04 Const. Testing IC: -0.0269
2011-01-04 Regression Testing IC: 0.2138

2011-02-01 Const. Testing IC: -0.0767
2011-02-01 Regression Testing IC: -0.0038

2011-03-08 Const. Testing IC: -0.1069
2011-03-08 Regression Testing IC: 0.1013

2011-04-07 Const. Testing IC: -0.0382
2011-04-07 Regression Testing IC: 0.1166

2011-05-06 Const. Testing IC: 0.1219
2011-05-06 Regression Testing IC: 0.0674

2011-06-03 Const. Testing IC: 0.1503
2011-06-03 Regression Testing IC: 0.0412

2011-07-04 Const. Testing IC: -0.0160
2011-07-04 Regression Testing IC: -0.1363

2011-08-01 Const. Testing IC: 0.0945
2011-08-01 Regression Testing IC: -0.0527

2011-08-29 Const. Testing IC: -0.1122
2011-08-29 Regression Testing IC: 0.1061

2011-09-27 Const. Testing IC: 0.0605
2011-09-27 Regression Testing IC: 0.1205

2011-11-01 Const. Testing IC: -0.0664
2011-11-01 Regression Testing IC: 0.0691

2011-11-29 Const. Testing IC: 0.3047
2011-11-29 Regression Testing IC: -0.1484

2011-12-27 Const. Testing IC: 0.1569
2011-12-27 Regression Testing IC: 0.0540

2012-02-02 Const. Testing IC: -0.1223
2012-02-02 Regression Testing IC: 0.1418

2012-03-01 Const. Testing IC: 0.1192
2012-03-01 Regression Testing IC: 0.0050

2012-03-29 Const. Testing IC: -0.0068
2012-03-29 Regression Testing IC: 0.1134

2012-05-03 Const. Testing IC: -0.0167
2012-05-03 Regression Testing IC: -0.0889

2012-05-31 Const. Testing IC: 0.1837
2012-05-31 Regression Testing IC: 0.0957

2012-06-29 Const. Testing IC: 0.0565
2012-06-29 Regression Testing IC: 0.0182

2012-07-27 Const. Testing IC: 0.0853
2012-07-27 Regression Testing IC: 0.0282

2012-08-24 Const. Testing IC: -0.0458
2012-08-24 Regression Testing IC: -0.0237

2012-09-21 Const. Testing IC: 0.0062
2012-09-21 Regression Testing IC: 0.0361

2012-10-26 Const. Testing IC: -0.0304
2012-10-26 Regression Testing IC: 0.0223

2012-11-23 Const. Testing IC: 0.1535
2012-11-23 Regression Testing IC: 0.1814

2012-12-21 Const. Testing IC: 0.0064
2012-12-21 Regression Testing IC: -0.0218

2013-01-23 Const. Testing IC: 0.0562
2013-01-23 Regression Testing IC: 0.0343

2013-02-27 Const. Testing IC: -0.0249
2013-02-27 Regression Testing IC: -0.0705

2013-03-27 Const. Testing IC: 0.0184
2013-03-27 Regression Testing IC: -0.0111

2013-04-26 Const. Testing IC: -0.0546
2013-04-26 Regression Testing IC: -0.0774

2013-05-29 Const. Testing IC: 0.1452
2013-05-29 Regression Testing IC: -0.2151

2013-07-01 Const. Testing IC: -0.0847
2013-07-01 Regression Testing IC: -0.0294

2013-07-29 Const. Testing IC: 0.0132
2013-07-29 Regression Testing IC: 0.0709

2013-08-26 Const. Testing IC: -0.1577
2013-08-26 Regression Testing IC: -0.1322

2013-09-25 Const. Testing IC: 0.0399
2013-09-25 Regression Testing IC: 0.1268

2013-10-30 Const. Testing IC: -0.0659
2013-10-30 Regression Testing IC: 0.0932

2013-11-27 Const. Testing IC: 0.1961
2013-11-27 Regression Testing IC: -0.1485

2013-12-25 Const. Testing IC: 0.0422
2013-12-25 Regression Testing IC: -0.0652

2014-01-23 Const. Testing IC: -0.1586
2014-01-23 Regression Testing IC: 0.0708

2014-02-27 Const. Testing IC: -0.0032
2014-02-27 Regression Testing IC: 0.2091

2014-03-27 Const. Testing IC: 0.0728
2014-03-27 Regression Testing IC: 0.0033

2014-04-25 Const. Testing IC: -0.0764
2014-04-25 Regression Testing IC: 0.0414

2014-05-27 Const. Testing IC: -0.0084
2014-05-27 Regression Testing IC: -0.0578

2014-06-25 Const. Testing IC: 0.0083
2014-06-25 Regression Testing IC: 0.1477

2014-07-23 Const. Testing IC: -0.1807
2014-07-23 Regression Testing IC: -0.0564

2014-08-20 Const. Testing IC: -0.1499
2014-08-20 Regression Testing IC: 0.0610

2014-09-18 Const. Testing IC: -0.0139
2014-09-18 Regression Testing IC: -0.0006

2014-10-23 Const. Testing IC: -0.1006
2014-10-23 Regression Testing IC: 0.1611

2014-11-20 Const. Testing IC: 0.1354
2014-11-20 Regression Testing IC: -0.0375

2014-12-18 Const. Testing IC: 0.2776
2014-12-18 Regression Testing IC: -0.2187

2015-01-19 Const. Testing IC: -0.0248
2015-01-19 Regression Testing IC: -0.0870

2015-02-16 Const. Testing IC: -0.1400
2015-02-16 Regression Testing IC: -0.0396

2015-03-23 Const. Testing IC: 0.0028
2015-03-23 Regression Testing IC: 0.0899

2015-04-21 Const. Testing IC: -0.0684
2015-04-21 Regression Testing IC: -0.1047

2015-05-20 Const. Testing IC: -0.1714
2015-05-20 Regression Testing IC: 0.0928

2015-06-17 Const. Testing IC: 0.2931
2015-06-17 Regression Testing IC: -0.0440

2015-07-16 Const. Testing IC: -0.1631
2015-07-16 Regression Testing IC: 0.0002

2015-08-13 Const. Testing IC: 0.1540
2015-08-13 Regression Testing IC: 0.1298

2015-09-14 Const. Testing IC: -0.0512
2015-09-14 Regression Testing IC: -0.0789

2015-10-19 Const. Testing IC: 0.0074
2015-10-19 Regression Testing IC: -0.0167

2015-11-16 Const. Testing IC: 0.1538
2015-11-16 Regression Testing IC: 0.2003

2015-12-14 Const. Testing IC: 0.0785
2015-12-14 Regression Testing IC: 0.0895

2016-01-12 Const. Testing IC: 0.0601
2016-01-12 Regression Testing IC: 0.0298

2016-02-16 Const. Testing IC: 0.1283
2016-02-16 Regression Testing IC: 0.1954

2016-03-15 Const. Testing IC: -0.1180
2016-03-15 Regression Testing IC: -0.1441

2016-04-13 Const. Testing IC: 0.1728
2016-04-13 Regression Testing IC: 0.1333

2016-05-12 Const. Testing IC: -0.0033
2016-05-12 Regression Testing IC: 0.0151

2016-06-13 Const. Testing IC: 0.0020
2016-06-13 Regression Testing IC: -0.0420

2016-07-11 Const. Testing IC: 0.1558
2016-07-11 Regression Testing IC: 0.2143

2016-08-08 Const. Testing IC: -0.0921
2016-08-08 Regression Testing IC: 0.0194

2016-09-05 Const. Testing IC: -0.0283
2016-09-05 Regression Testing IC: -0.0607

2016-10-12 Const. Testing IC: -0.0389
2016-10-12 Regression Testing IC: 0.0302

2016-11-09 Const. Testing IC: 0.0158
2016-11-09 Regression Testing IC: 0.0784

2016-12-07 Const. Testing IC: -0.0444
2016-12-07 Regression Testing IC: 0.0526

2017-01-05 Const. Testing IC: 0.1744
2017-01-05 Regression Testing IC: -0.1081

2017-02-09 Const. Testing IC: 0.0515
2017-02-09 Regression Testing IC: -0.0642

2017-03-09 Const. Testing IC: 0.2282
2017-03-09 Regression Testing IC: -0.0151

2017-04-10 Const. Testing IC: 0.1924
2017-04-10 Regression Testing IC: 0.0111

2017-05-09 Const. Testing IC: 0.2467
2017-05-09 Regression Testing IC: 0.1482

2017-06-08 Const. Testing IC: 0.1690
2017-06-08 Regression Testing IC: 0.1567

2017-07-06 Const. Testing IC: 0.0727
2017-07-06 Regression Testing IC: 0.1572

2017-08-03 Const. Testing IC: -0.0659
2017-08-03 Regression Testing IC: -0.0862

2017-08-31 Const. Testing IC: 0.0314
2017-08-31 Regression Testing IC: -0.0116

2017-09-28 Const. Testing IC: 0.2740
2017-09-28 Regression Testing IC: 0.0627

2017-11-02 Const. Testing IC: 0.1258
2017-11-02 Regression Testing IC: 0.1926

2017-11-30 Const. Testing IC: 0.1382
2017-11-30 Regression Testing IC: 0.0374

2017-12-28 Const. Testing IC: 0.1765
2017-12-28 Regression Testing IC: 0.1723

2018-01-26 Const. Testing IC: 0.0971
2018-01-26 Regression Testing IC: 0.0475

2018-03-02 Const. Testing IC: -0.1221
2018-03-02 Regression Testing IC: -0.1051

2018-03-30 Const. Testing IC: -0.0237
2018-03-30 Regression Testing IC: -0.0487

2018-05-03 Const. Testing IC: 0.1240
2018-05-03 Regression Testing IC: 0.1136

2018-05-31 Const. Testing IC: 0.2084
2018-05-31 Regression Testing IC: 0.1941

2018-06-29 Const. Testing IC: 0.0225
2018-06-29 Regression Testing IC: 0.0276

2018-07-27 Const. Testing IC: -0.0387
2018-07-27 Regression Testing IC: 0.0244

2018-08-24 Const. Testing IC: -0.0239
2018-08-24 Regression Testing IC: 0.0173

2018-09-21 Const. Testing IC: -0.0247
2018-09-21 Regression Testing IC: -0.0042

2018-10-29 Const. Testing IC: -0.0981
2018-10-29 Regression Testing IC: -0.0643

2018-11-26 Const. Testing IC: 0.1876
2018-11-26 Regression Testing IC: 0.1411

2018-12-24 Const. Testing IC: 0.0001
2018-12-24 Regression Testing IC: 0.0181

In [10]:
model_df[['naive ic.', 'regress ic.']].agg(['mean', 'std'])


Out[10]:
naive ic. regress ic.
mean 0.032286 0.027784
std 0.116897 0.099669

在这个例子中,线性回归模型的IC值略微高于Naive模型。

回测( simple long short strategy)



In [11]:
industry_name = 'sw_adj'
industry_level = 1

industry_names = industry_list(industry_name, industry_level)
industry_total = engine.fetch_industry_matrix_range(universe, dates=model_dates, category=industry_name, level=industry_level)

dx_return_data = engine.fetch_dx_return_range(universe=universe,
                                              dates=model_dates,
                                              horizon=horizon)

In [12]:
dx_return_data.head()


Out[12]:
trade_date code dx
39139 2011-01-04 1 -0.036793
39188 2011-01-04 2 -0.072883
98 2011-01-04 5 -0.066037
104 2011-01-04 6 -0.012519
39309 2011-01-04 9 0.059210

In [14]:
rets1 = []
rets2 = []

for i, ref_date in enumerate(model_dates):
    py_ref_date = dt.datetime.strptime(ref_date, '%Y-%m-%d')
    industry_matrix = industry_total[industry_total.trade_date == ref_date]
    dx_returns = dx_return_data[dx_return_data.trade_date == py_ref_date][['code', 'dx']]
    
    res = pd.merge(dx_returns, industry_matrix, on=['code']).dropna()
    codes = res.code.values.tolist()
    
    alpha_logger.info('{0} full re-balance: {1}'.format(ref_date, len(codes)))
    
    x_test, _ = test_data[ref_date]
    
    ## naive model
    
    raw_predict1 = const_composer.predict(ref_date, x=x_test)[0].reindex(codes)
    er1 = raw_predict1.fillna(raw_predict1.median()).values
    
    target_pos1, _ = er_portfolio_analysis(er1,
                                           res.industry_name.values,
                                           None,
                                           None,
                                           False,
                                           None,
                                           method='ls')
        
    target_pos1['code'] = codes
    result1 = pd.merge(target_pos1, dx_returns, on=['code'])
    ret1 = result1.weight.values @ (np.exp(result1.dx.values) - 1.)
    rets1.append(np.log(1. + ret1))

    ## regression model
    
    raw_predict2 = regression_composer.predict(ref_date, x=x_test)[0].reindex(codes)
    er2 = raw_predict2.fillna(raw_predict2.median()).values
    
    target_pos2, _ = er_portfolio_analysis(er2,
                                           res.industry_name.values,
                                           None,
                                           None,
                                           False,
                                           None,
                                           method='ls')
    
    target_pos2['code'] = codes
    result2 = pd.merge(target_pos2, dx_returns, on=['code'])
    ret2 = result2.weight.values @ (np.exp(result2.dx.values) - 1.)
    rets2.append(np.log(1. + ret2))
    
    alpha_logger.info('{0} is finished'.format(ref_date))


2019-02-10 00:07:59,902 - ALPHA_MIND - INFO - 2011-01-04 full re-balance: 799
2019-02-10 00:07:59,927 - ALPHA_MIND - INFO - 2011-01-04 is finished
2019-02-10 00:07:59,937 - ALPHA_MIND - INFO - 2011-02-01 full re-balance: 798
2019-02-10 00:07:59,953 - ALPHA_MIND - INFO - 2011-02-01 is finished
2019-02-10 00:07:59,963 - ALPHA_MIND - INFO - 2011-03-08 full re-balance: 798
2019-02-10 00:07:59,979 - ALPHA_MIND - INFO - 2011-03-08 is finished
2019-02-10 00:07:59,990 - ALPHA_MIND - INFO - 2011-04-07 full re-balance: 798
2019-02-10 00:08:00,007 - ALPHA_MIND - INFO - 2011-04-07 is finished
2019-02-10 00:08:00,019 - ALPHA_MIND - INFO - 2011-05-06 full re-balance: 798
2019-02-10 00:08:00,037 - ALPHA_MIND - INFO - 2011-05-06 is finished
2019-02-10 00:08:00,047 - ALPHA_MIND - INFO - 2011-06-03 full re-balance: 798
2019-02-10 00:08:00,063 - ALPHA_MIND - INFO - 2011-06-03 is finished
2019-02-10 00:08:00,074 - ALPHA_MIND - INFO - 2011-07-04 full re-balance: 798
2019-02-10 00:08:00,090 - ALPHA_MIND - INFO - 2011-07-04 is finished
2019-02-10 00:08:00,099 - ALPHA_MIND - INFO - 2011-08-01 full re-balance: 797
2019-02-10 00:08:00,116 - ALPHA_MIND - INFO - 2011-08-01 is finished
2019-02-10 00:08:00,126 - ALPHA_MIND - INFO - 2011-08-29 full re-balance: 796
2019-02-10 00:08:00,144 - ALPHA_MIND - INFO - 2011-08-29 is finished
2019-02-10 00:08:00,153 - ALPHA_MIND - INFO - 2011-09-27 full re-balance: 797
2019-02-10 00:08:00,169 - ALPHA_MIND - INFO - 2011-09-27 is finished
2019-02-10 00:08:00,181 - ALPHA_MIND - INFO - 2011-11-01 full re-balance: 798
2019-02-10 00:08:00,197 - ALPHA_MIND - INFO - 2011-11-01 is finished
2019-02-10 00:08:00,209 - ALPHA_MIND - INFO - 2011-11-29 full re-balance: 798
2019-02-10 00:08:00,224 - ALPHA_MIND - INFO - 2011-11-29 is finished
2019-02-10 00:08:00,233 - ALPHA_MIND - INFO - 2011-12-27 full re-balance: 798
2019-02-10 00:08:00,251 - ALPHA_MIND - INFO - 2011-12-27 is finished
2019-02-10 00:08:00,262 - ALPHA_MIND - INFO - 2012-02-02 full re-balance: 798
2019-02-10 00:08:00,278 - ALPHA_MIND - INFO - 2012-02-02 is finished
2019-02-10 00:08:00,289 - ALPHA_MIND - INFO - 2012-03-01 full re-balance: 797
2019-02-10 00:08:00,305 - ALPHA_MIND - INFO - 2012-03-01 is finished
2019-02-10 00:08:00,316 - ALPHA_MIND - INFO - 2012-03-29 full re-balance: 796
2019-02-10 00:08:00,332 - ALPHA_MIND - INFO - 2012-03-29 is finished
2019-02-10 00:08:00,345 - ALPHA_MIND - INFO - 2012-05-03 full re-balance: 798
2019-02-10 00:08:00,363 - ALPHA_MIND - INFO - 2012-05-03 is finished
2019-02-10 00:08:00,374 - ALPHA_MIND - INFO - 2012-05-31 full re-balance: 798
2019-02-10 00:08:00,390 - ALPHA_MIND - INFO - 2012-05-31 is finished
2019-02-10 00:08:00,399 - ALPHA_MIND - INFO - 2012-06-29 full re-balance: 798
2019-02-10 00:08:00,414 - ALPHA_MIND - INFO - 2012-06-29 is finished
2019-02-10 00:08:00,427 - ALPHA_MIND - INFO - 2012-07-27 full re-balance: 798
2019-02-10 00:08:00,444 - ALPHA_MIND - INFO - 2012-07-27 is finished
2019-02-10 00:08:00,454 - ALPHA_MIND - INFO - 2012-08-24 full re-balance: 799
2019-02-10 00:08:00,474 - ALPHA_MIND - INFO - 2012-08-24 is finished
2019-02-10 00:08:00,484 - ALPHA_MIND - INFO - 2012-09-21 full re-balance: 799
2019-02-10 00:08:00,500 - ALPHA_MIND - INFO - 2012-09-21 is finished
2019-02-10 00:08:00,511 - ALPHA_MIND - INFO - 2012-10-26 full re-balance: 799
2019-02-10 00:08:00,528 - ALPHA_MIND - INFO - 2012-10-26 is finished
2019-02-10 00:08:00,539 - ALPHA_MIND - INFO - 2012-11-23 full re-balance: 799
2019-02-10 00:08:00,559 - ALPHA_MIND - INFO - 2012-11-23 is finished
2019-02-10 00:08:00,573 - ALPHA_MIND - INFO - 2012-12-21 full re-balance: 799
2019-02-10 00:08:00,592 - ALPHA_MIND - INFO - 2012-12-21 is finished
2019-02-10 00:08:00,603 - ALPHA_MIND - INFO - 2013-01-23 full re-balance: 799
2019-02-10 00:08:00,621 - ALPHA_MIND - INFO - 2013-01-23 is finished
2019-02-10 00:08:00,633 - ALPHA_MIND - INFO - 2013-02-27 full re-balance: 800
2019-02-10 00:08:00,653 - ALPHA_MIND - INFO - 2013-02-27 is finished
2019-02-10 00:08:00,663 - ALPHA_MIND - INFO - 2013-03-27 full re-balance: 800
2019-02-10 00:08:00,683 - ALPHA_MIND - INFO - 2013-03-27 is finished
2019-02-10 00:08:00,695 - ALPHA_MIND - INFO - 2013-04-26 full re-balance: 800
2019-02-10 00:08:00,716 - ALPHA_MIND - INFO - 2013-04-26 is finished
2019-02-10 00:08:00,728 - ALPHA_MIND - INFO - 2013-05-29 full re-balance: 800
2019-02-10 00:08:00,745 - ALPHA_MIND - INFO - 2013-05-29 is finished
2019-02-10 00:08:00,758 - ALPHA_MIND - INFO - 2013-07-01 full re-balance: 800
2019-02-10 00:08:00,777 - ALPHA_MIND - INFO - 2013-07-01 is finished
2019-02-10 00:08:00,787 - ALPHA_MIND - INFO - 2013-07-29 full re-balance: 800
2019-02-10 00:08:00,807 - ALPHA_MIND - INFO - 2013-07-29 is finished
2019-02-10 00:08:00,817 - ALPHA_MIND - INFO - 2013-08-26 full re-balance: 800
2019-02-10 00:08:00,836 - ALPHA_MIND - INFO - 2013-08-26 is finished
2019-02-10 00:08:00,846 - ALPHA_MIND - INFO - 2013-09-25 full re-balance: 799
2019-02-10 00:08:00,864 - ALPHA_MIND - INFO - 2013-09-25 is finished
2019-02-10 00:08:00,876 - ALPHA_MIND - INFO - 2013-10-30 full re-balance: 800
2019-02-10 00:08:00,894 - ALPHA_MIND - INFO - 2013-10-30 is finished
2019-02-10 00:08:00,906 - ALPHA_MIND - INFO - 2013-11-27 full re-balance: 800
2019-02-10 00:08:00,927 - ALPHA_MIND - INFO - 2013-11-27 is finished
2019-02-10 00:08:00,938 - ALPHA_MIND - INFO - 2013-12-25 full re-balance: 800
2019-02-10 00:08:00,957 - ALPHA_MIND - INFO - 2013-12-25 is finished
2019-02-10 00:08:00,969 - ALPHA_MIND - INFO - 2014-01-23 full re-balance: 800
2019-02-10 00:08:00,989 - ALPHA_MIND - INFO - 2014-01-23 is finished
2019-02-10 00:08:00,999 - ALPHA_MIND - INFO - 2014-02-27 full re-balance: 800
2019-02-10 00:08:01,017 - ALPHA_MIND - INFO - 2014-02-27 is finished
2019-02-10 00:08:01,028 - ALPHA_MIND - INFO - 2014-03-27 full re-balance: 800
2019-02-10 00:08:01,043 - ALPHA_MIND - INFO - 2014-03-27 is finished
2019-02-10 00:08:01,054 - ALPHA_MIND - INFO - 2014-04-25 full re-balance: 800
2019-02-10 00:08:01,074 - ALPHA_MIND - INFO - 2014-04-25 is finished
2019-02-10 00:08:01,085 - ALPHA_MIND - INFO - 2014-05-27 full re-balance: 800
2019-02-10 00:08:01,101 - ALPHA_MIND - INFO - 2014-05-27 is finished
2019-02-10 00:08:01,112 - ALPHA_MIND - INFO - 2014-06-25 full re-balance: 800
2019-02-10 00:08:01,128 - ALPHA_MIND - INFO - 2014-06-25 is finished
2019-02-10 00:08:01,138 - ALPHA_MIND - INFO - 2014-07-23 full re-balance: 800
2019-02-10 00:08:01,155 - ALPHA_MIND - INFO - 2014-07-23 is finished
2019-02-10 00:08:01,164 - ALPHA_MIND - INFO - 2014-08-20 full re-balance: 800
2019-02-10 00:08:01,183 - ALPHA_MIND - INFO - 2014-08-20 is finished
2019-02-10 00:08:01,195 - ALPHA_MIND - INFO - 2014-09-18 full re-balance: 800
2019-02-10 00:08:01,212 - ALPHA_MIND - INFO - 2014-09-18 is finished
2019-02-10 00:08:01,222 - ALPHA_MIND - INFO - 2014-10-23 full re-balance: 800
2019-02-10 00:08:01,241 - ALPHA_MIND - INFO - 2014-10-23 is finished
2019-02-10 00:08:01,251 - ALPHA_MIND - INFO - 2014-11-20 full re-balance: 800
2019-02-10 00:08:01,268 - ALPHA_MIND - INFO - 2014-11-20 is finished
2019-02-10 00:08:01,279 - ALPHA_MIND - INFO - 2014-12-18 full re-balance: 800
2019-02-10 00:08:01,296 - ALPHA_MIND - INFO - 2014-12-18 is finished
2019-02-10 00:08:01,308 - ALPHA_MIND - INFO - 2015-01-19 full re-balance: 800
2019-02-10 00:08:01,323 - ALPHA_MIND - INFO - 2015-01-19 is finished
2019-02-10 00:08:01,333 - ALPHA_MIND - INFO - 2015-02-16 full re-balance: 800
2019-02-10 00:08:01,348 - ALPHA_MIND - INFO - 2015-02-16 is finished
2019-02-10 00:08:01,359 - ALPHA_MIND - INFO - 2015-03-23 full re-balance: 800
2019-02-10 00:08:01,377 - ALPHA_MIND - INFO - 2015-03-23 is finished
2019-02-10 00:08:01,386 - ALPHA_MIND - INFO - 2015-04-21 full re-balance: 800
2019-02-10 00:08:01,403 - ALPHA_MIND - INFO - 2015-04-21 is finished
2019-02-10 00:08:01,413 - ALPHA_MIND - INFO - 2015-05-20 full re-balance: 798
2019-02-10 00:08:01,429 - ALPHA_MIND - INFO - 2015-05-20 is finished
2019-02-10 00:08:01,441 - ALPHA_MIND - INFO - 2015-06-17 full re-balance: 800
2019-02-10 00:08:01,459 - ALPHA_MIND - INFO - 2015-06-17 is finished
2019-02-10 00:08:01,469 - ALPHA_MIND - INFO - 2015-07-16 full re-balance: 800
2019-02-10 00:08:01,486 - ALPHA_MIND - INFO - 2015-07-16 is finished
2019-02-10 00:08:01,496 - ALPHA_MIND - INFO - 2015-08-13 full re-balance: 800
2019-02-10 00:08:01,513 - ALPHA_MIND - INFO - 2015-08-13 is finished
2019-02-10 00:08:01,524 - ALPHA_MIND - INFO - 2015-09-14 full re-balance: 800
2019-02-10 00:08:01,540 - ALPHA_MIND - INFO - 2015-09-14 is finished
2019-02-10 00:08:01,549 - ALPHA_MIND - INFO - 2015-10-19 full re-balance: 800
2019-02-10 00:08:01,563 - ALPHA_MIND - INFO - 2015-10-19 is finished
2019-02-10 00:08:01,575 - ALPHA_MIND - INFO - 2015-11-16 full re-balance: 800
2019-02-10 00:08:01,591 - ALPHA_MIND - INFO - 2015-11-16 is finished
2019-02-10 00:08:01,601 - ALPHA_MIND - INFO - 2015-12-14 full re-balance: 800
2019-02-10 00:08:01,617 - ALPHA_MIND - INFO - 2015-12-14 is finished
2019-02-10 00:08:01,627 - ALPHA_MIND - INFO - 2016-01-12 full re-balance: 800
2019-02-10 00:08:01,642 - ALPHA_MIND - INFO - 2016-01-12 is finished
2019-02-10 00:08:01,654 - ALPHA_MIND - INFO - 2016-02-16 full re-balance: 800
2019-02-10 00:08:01,669 - ALPHA_MIND - INFO - 2016-02-16 is finished
2019-02-10 00:08:01,678 - ALPHA_MIND - INFO - 2016-03-15 full re-balance: 800
2019-02-10 00:08:01,694 - ALPHA_MIND - INFO - 2016-03-15 is finished
2019-02-10 00:08:01,707 - ALPHA_MIND - INFO - 2016-04-13 full re-balance: 800
2019-02-10 00:08:01,722 - ALPHA_MIND - INFO - 2016-04-13 is finished
2019-02-10 00:08:01,732 - ALPHA_MIND - INFO - 2016-05-12 full re-balance: 800
2019-02-10 00:08:01,747 - ALPHA_MIND - INFO - 2016-05-12 is finished
2019-02-10 00:08:01,759 - ALPHA_MIND - INFO - 2016-06-13 full re-balance: 800
2019-02-10 00:08:01,774 - ALPHA_MIND - INFO - 2016-06-13 is finished
2019-02-10 00:08:01,785 - ALPHA_MIND - INFO - 2016-07-11 full re-balance: 800
2019-02-10 00:08:01,801 - ALPHA_MIND - INFO - 2016-07-11 is finished
2019-02-10 00:08:01,810 - ALPHA_MIND - INFO - 2016-08-08 full re-balance: 800
2019-02-10 00:08:01,825 - ALPHA_MIND - INFO - 2016-08-08 is finished
2019-02-10 00:08:01,837 - ALPHA_MIND - INFO - 2016-09-05 full re-balance: 800
2019-02-10 00:08:01,853 - ALPHA_MIND - INFO - 2016-09-05 is finished
2019-02-10 00:08:01,862 - ALPHA_MIND - INFO - 2016-10-12 full re-balance: 800
2019-02-10 00:08:01,877 - ALPHA_MIND - INFO - 2016-10-12 is finished
2019-02-10 00:08:01,887 - ALPHA_MIND - INFO - 2016-11-09 full re-balance: 800
2019-02-10 00:08:01,903 - ALPHA_MIND - INFO - 2016-11-09 is finished
2019-02-10 00:08:01,912 - ALPHA_MIND - INFO - 2016-12-07 full re-balance: 800
2019-02-10 00:08:01,926 - ALPHA_MIND - INFO - 2016-12-07 is finished
2019-02-10 00:08:01,936 - ALPHA_MIND - INFO - 2017-01-05 full re-balance: 800
2019-02-10 00:08:01,950 - ALPHA_MIND - INFO - 2017-01-05 is finished
2019-02-10 00:08:01,959 - ALPHA_MIND - INFO - 2017-02-09 full re-balance: 800
2019-02-10 00:08:01,975 - ALPHA_MIND - INFO - 2017-02-09 is finished
2019-02-10 00:08:01,987 - ALPHA_MIND - INFO - 2017-03-09 full re-balance: 800
2019-02-10 00:08:02,001 - ALPHA_MIND - INFO - 2017-03-09 is finished
2019-02-10 00:08:02,011 - ALPHA_MIND - INFO - 2017-04-10 full re-balance: 800
2019-02-10 00:08:02,025 - ALPHA_MIND - INFO - 2017-04-10 is finished
2019-02-10 00:08:02,035 - ALPHA_MIND - INFO - 2017-05-09 full re-balance: 800
2019-02-10 00:08:02,051 - ALPHA_MIND - INFO - 2017-05-09 is finished
2019-02-10 00:08:02,061 - ALPHA_MIND - INFO - 2017-06-08 full re-balance: 800
2019-02-10 00:08:02,077 - ALPHA_MIND - INFO - 2017-06-08 is finished
2019-02-10 00:08:02,086 - ALPHA_MIND - INFO - 2017-07-06 full re-balance: 800
2019-02-10 00:08:02,101 - ALPHA_MIND - INFO - 2017-07-06 is finished
2019-02-10 00:08:02,111 - ALPHA_MIND - INFO - 2017-08-03 full re-balance: 800
2019-02-10 00:08:02,128 - ALPHA_MIND - INFO - 2017-08-03 is finished
2019-02-10 00:08:02,139 - ALPHA_MIND - INFO - 2017-08-31 full re-balance: 800
2019-02-10 00:08:02,154 - ALPHA_MIND - INFO - 2017-08-31 is finished
2019-02-10 00:08:02,164 - ALPHA_MIND - INFO - 2017-09-28 full re-balance: 800
2019-02-10 00:08:02,178 - ALPHA_MIND - INFO - 2017-09-28 is finished
2019-02-10 00:08:02,190 - ALPHA_MIND - INFO - 2017-11-02 full re-balance: 800
2019-02-10 00:08:02,205 - ALPHA_MIND - INFO - 2017-11-02 is finished
2019-02-10 00:08:02,216 - ALPHA_MIND - INFO - 2017-11-30 full re-balance: 800
2019-02-10 00:08:02,232 - ALPHA_MIND - INFO - 2017-11-30 is finished
2019-02-10 00:08:02,242 - ALPHA_MIND - INFO - 2017-12-28 full re-balance: 800
2019-02-10 00:08:02,257 - ALPHA_MIND - INFO - 2017-12-28 is finished
2019-02-10 00:08:02,267 - ALPHA_MIND - INFO - 2018-01-26 full re-balance: 800
2019-02-10 00:08:02,282 - ALPHA_MIND - INFO - 2018-01-26 is finished
2019-02-10 00:08:02,293 - ALPHA_MIND - INFO - 2018-03-02 full re-balance: 800
2019-02-10 00:08:02,309 - ALPHA_MIND - INFO - 2018-03-02 is finished
2019-02-10 00:08:02,318 - ALPHA_MIND - INFO - 2018-03-30 full re-balance: 800
2019-02-10 00:08:02,334 - ALPHA_MIND - INFO - 2018-03-30 is finished
2019-02-10 00:08:02,344 - ALPHA_MIND - INFO - 2018-05-03 full re-balance: 800
2019-02-10 00:08:02,359 - ALPHA_MIND - INFO - 2018-05-03 is finished
2019-02-10 00:08:02,369 - ALPHA_MIND - INFO - 2018-05-31 full re-balance: 800
2019-02-10 00:08:02,384 - ALPHA_MIND - INFO - 2018-05-31 is finished
2019-02-10 00:08:02,394 - ALPHA_MIND - INFO - 2018-06-29 full re-balance: 800
2019-02-10 00:08:02,410 - ALPHA_MIND - INFO - 2018-06-29 is finished
2019-02-10 00:08:02,420 - ALPHA_MIND - INFO - 2018-07-27 full re-balance: 800
2019-02-10 00:08:02,436 - ALPHA_MIND - INFO - 2018-07-27 is finished
2019-02-10 00:08:02,445 - ALPHA_MIND - INFO - 2018-08-24 full re-balance: 800
2019-02-10 00:08:02,461 - ALPHA_MIND - INFO - 2018-08-24 is finished
2019-02-10 00:08:02,471 - ALPHA_MIND - INFO - 2018-09-21 full re-balance: 800
2019-02-10 00:08:02,485 - ALPHA_MIND - INFO - 2018-09-21 is finished
2019-02-10 00:08:02,494 - ALPHA_MIND - INFO - 2018-10-29 full re-balance: 800
2019-02-10 00:08:02,511 - ALPHA_MIND - INFO - 2018-10-29 is finished
2019-02-10 00:08:02,521 - ALPHA_MIND - INFO - 2018-11-26 full re-balance: 800
2019-02-10 00:08:02,536 - ALPHA_MIND - INFO - 2018-11-26 is finished
2019-02-10 00:08:02,545 - ALPHA_MIND - INFO - 2018-12-24 full re-balance: 800
2019-02-10 00:08:02,561 - ALPHA_MIND - INFO - 2018-12-24 is finished

In [15]:
ret_df = pd.DataFrame({'naive': rets1, 'regress': rets2}, index=model_dates)
ret_df.loc[advanceDateByCalendar('china.sse', model_dates[-1], freq).strftime('%Y-%m-%d')] = 0.
ret_df = ret_df.shift(1)
ret_df.iloc[0] = 0.

ret_df[['naive', 'regress']].cumsum().plot(figsize=(12, 6),
                                             title='Fixed freq rebalanced: {0}'.format(freq))


Out[15]:
<matplotlib.axes._subplots.AxesSubplot at 0x2e2bc41e4a8>

In [ ]: